
public abstract class MembershipFunction {
	
	protected double[] sampledValues;
	protected double lowerBound;
	
	public static double RESOLUTION = 0.1;	// the "dx"
	
	/*
	 * Returns an approximate value of the membership function at x
	 * (Specifically, returns the pre-calculated value mapped to the domain 
	 * element closest to x)
	 */
	public double getValue(double x) {
		int index = (int)((x - lowerBound) / RESOLUTION);
		return (index >= 0 && index < sampledValues.length && x >= lowerBound) ? 
				sampledValues[index] : 0;
	}
	
	/*
	 * Returns a copy of the sampledValues array, qualified by firingStrength
	 * That is, each value in the array is the min of firingStrength and the 
	 * membership function value
	 */
	public double[] getQualifiedValues(double firingStrength) {
		double[] qualifiedValues = new double[sampledValues.length];
		for (int i = 0; i < qualifiedValues.length; i++) {
			qualifiedValues[i] = Math.min(firingStrength, sampledValues[i]);
		}
		return qualifiedValues;
	}
	
	public double getLowerBound() { return lowerBound; }
}
